﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace Google.Translates.Core.Entries
{
    //{ "data": { "translations": [ { "translatedText": "Wind" } ] } } 

    /*
     200 OK

    {
        "data": {
            "translations": [
                {
                    "translatedText": "Hallo Welt",
                    "detectedSourceLanguage": "en"
                }
            ]
        }
    }

     */

    [DataContract]
    public class TranslationResult
    {
        /// <summary>
        /// Value for JSON data
        /// </summary>
        [DataMember(Name="data")]
        public TranslationData Data { get; set; }

        public string GetAllTranslationText()
        {
            var sbReVal = new StringBuilder();
            foreach (var trans in Data.Translations)
                sbReVal.Append(trans.TranslatedText.Replace("\r","\r\n"));
            return sbReVal.ToString();
        }

        public string GetFirstSourceLanguageKey()
        {
            if (Data == null || Data.Translations == null || Data.Translations.Length < 1 
                || string.IsNullOrEmpty(Data.Translations[0].DetectedSourceLanguage)) return "";
            return Data.Translations[0].DetectedSourceLanguage;
        }
    }
}
